namespace TestProject1
{
    [TestClass]
    public class OrderTests
    {
        [TestMethod]
        public void Order_Constructor_SetsProperties_Correctly()
        {
           
            string expectedOrderNumber = "001";
            Customer expectedCustomer = new Customer(001, "sjj", "123");

           
            Order order = new Order(expectedOrderNumber, expectedCustomer);

            
            Assert.AreEqual(expectedOrderNumber, order.OrderNumber);
            Assert.AreEqual(expectedCustomer, order.Customer);
            Assert.IsFalse(order.OrderDetailsList.Any());
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void AddOrderDetail_ThrowsException_WhenDetailAlreadyExists()
        {
            
            Order order = new Order("001", new Customer(001, "sjj", "123456"));
            OrderDetails existingDetail = new OrderDetails(001, new Product(001, "Product A", 10.0m), 1);
            OrderDetails newDetail = new OrderDetails(001, new Product(001, "Product A", 10.0m), 1);

           
            order.AddOrderDetail(existingDetail); 
            order.AddOrderDetail(newDetail); 

        }

        [TestMethod]
        public void RemoveOrderDetail_RemovesDetail_Successfully()
        {
            
            Order order = new Order("001", new Customer(001, "sjj", "123456"));
            OrderDetails detail = new OrderDetails(1, new Product(001, "Product A", 10.0m), 1);
            order.AddOrderDetail(detail);

            
            bool removed = order.RemoveOrderDetail(detail.ProductId);

            
            Assert.IsTrue(removed);
            Assert.IsFalse(order.OrderDetailsList.Any());
        }
    }
    [TestClass]
    public class OrderDetailsTests
    {
        [TestMethod]
        public void OrderDetails_Equals_ReturnsTrue_WhenDetailsAreTheSame()
        {
           
            OrderDetails detail1 = new OrderDetails(001, new Product(001, "Product A", 10.0m), 1);
            OrderDetails detail2 = new OrderDetails(001, new Product(001, "Product A", 10.0m), 1);

            
            Assert.IsTrue(detail1.Equals(detail2));
        }

        [TestMethod]
        public void OrderDetails_Equals_ReturnsFalse_WhenDetailsAreDifferent()
        {
            
            OrderDetails detail1 = new OrderDetails(001, new Product(001, "Product A", 10.0m), 1);
            OrderDetails detail2 = new OrderDetails(002, new Product(002, "Product B", 20.0m), 1);

            
            Assert.IsFalse(detail1.Equals(detail2));
        }
    }
    [TestClass]
    public class OrderServiceTests
    {
        [TestMethod]
        public void AddOrder_AddsOrder_Successfully()
        {
            
            var orderService = new OrderService();
            Order order = new Order("001", new Customer(001, "sjj", "123456"));

            
            orderService.AddOrder(order);

            
            Order retrievedOrder = orderService._orders.FirstOrDefault(o => o.OrderNumber == "001");
            Assert.IsNotNull(retrievedOrder);
            Assert.AreEqual("001", retrievedOrder.OrderNumber);
        }

        [TestMethod]
        [ExpectedException(typeof(ArgumentException))]
        public void AddOrder_ThrowsException_WhenOrderNumberExists()
        {
           
            var orderService = new OrderService();
            Order order1 = new Order("001", new Customer(001, "sjj", "123456"));
            Order order2 = new Order("001", new Customer(002, "hjl", "654321"));

            
            orderService.AddOrder(order1); 
            orderService.AddOrder(order2); 

        }

    }
}